{extend name="platform/base" /}
{block name="resources"/}
<style>
.table{width:98%;display:table;border-left:1px dotted #e5e5e5;border-right:1px dotted #e5e5e5;border-bottom:1px dotted #e5e5e5;background:rgba(204,204,204,.09);padding:0 10px 10px 10px}
.table-body{min-height:50px;max-height:410px;overflow-y:auto;overflow-x:hidden}
.inline-block{display:inline-block}
.w5{width:5%}
.w75{width:70%}
.w19{width:10%;text-align:center}
.w100{width:100%;height:40px;line-height:40px;border-bottom:1px dotted #e5e5e5}
.add-spec{height:40px;line-height:40px;border-bottom:1px dotted #E6E6E6}
input{vertical-align:initial}
.table input[type=text],input.password,input.text,input[type=password]{font:12px/20px Arial;color:#777;background-color:#FFF;vertical-align:baseline;margin-bottom:0}
.set-style dl dt{text-align:left;width:7%}
label.line-label{display:inline-block;margin-right:10px;font-weight:400}
.edit_button{background-color:#53b567;border-color:#4bae5f;color:#fff;width:80px;line-height:30px;border:0}
.textarea-common{border-radius:0!important;resize:none!important;width:250px!important;box-sizing:border-box!important}
.h100{height:100px;}
</style>
{/block} {block name="main"}
<section class="panel panel-default">
	<header class="panel-heading font-bold"> 修改规格 </header>
	<div class="panel-body">
		<div class="form-horizontal" id="goods_brand_form" name="form">
			<div class="form-group">
				<label class="col-sm-2 control-label"><span class="color-red">*</span>规格名称</label>
				<div class="col-md-2">
					<input type="text" class="form-control" id="spec_name" name="spec_name" value="{$info.spec_name}" placeholder="请输入规格名称" required>
				</div>
			<p class="error">规格名称不能为空</p>
			</div>
            <div class="line line-dashed line-lg pull-in"></div>
            <div class="form-group">
				<label class="col-sm-2 control-label">规格排序</label>
				<div class="col-md-1">
					<input type="text" class="form-control" id="sort" value="{$info.sort}" onkeyup='this.value=this.value.replace(/\D/gi,"")' required>
				</div>

			</div>
            <div class="line line-dashed line-lg pull-in"></div>
            <div class="form-group">
				<label class="col-sm-2 control-label">是否启用</label>
				<div class="col-md-4">
					<label class="switch">
                         <input id="is_visible" type="checkbox" {eq name="info['is_visible']" value="1"}checked="checked"{/eq}>
                         <span></span> 
                    </label>
				</div>
			</div>
			
			<div class="line line-dashed line-lg pull-in"></div>
            <div class="form-group">
				<label class="col-sm-2 control-label">规格值：</label>
				<div class="col-md-4">

                         <textarea rows="" cols="" id="spec_value" class="textarea-common h100">{foreach name="info['spec_value_list']" item="v" key=key+1}{$v['spec_value_name']}&#10;{/foreach}</textarea>
						 <p class="hint" style="color: #BBB;margin-top: 10px;">一行为一个规格项，多个规格项用换行输入</p>
               
				</div>
			</div>
			
			<div class="line line-dashed line-lg pull-in"></div>
            <div class="form-group">
				<label class="col-sm-2 control-label">规格说明：</label>
				<div class="col-md-4">
                        <textarea class="textarea-common" placeholder="请输入规格说明" id="spec_des">{$info['spec_des']}</textarea>
				</div>
			</div>
			
            <div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<div class="col-sm-4 col-sm-offset-2">
					<button class="edit_button" onclick="updateGoodsSpec();">提交</button>
				</div>
			</div>
		</div>
	</div>
</section>
<input type="hidden" id="spec_id" name="spec_id" value="{$info['spec_id']}">
<script>
function validation() {
	var spec_name = $("#spec_name");
	if (spec_name.val() == "") {
		spec_name.focus().next("span").show();
		return false;
	} else {
		spec_name.next("span").hide();
	}
	return true;
}

var flag = false;//防止重复提交
function updateGoodsSpec() {
	
	if (!validation()) {
		return;
	}
	var spec_id = $("#spec_id").val();
	var spec_name = $("#spec_name").val();
	var sort = $("#sort").val();
	var show_type = 1;
	var spec_des = $('#spec_des').val();
	if ($("#is_visible").prop("checked")) {
		var is_visible = 1;
	} else {
		var is_visible = 0;
	}
	if ($("#is_screen").prop("checked")) {
		var is_screen = 1;
	} else {
		var is_screen = 0;
	}
	
	var spec_value_str = $('#spec_value').val();
	var reg = new RegExp("\n","g");//g,表示全部替换。
	var space = new RegExp(" ","g");
	spec_value_str = spec_value_str.replace(reg, ",");

	spec_value_arr = spec_value_str.split(',');
	for(i in spec_value_arr){
		if(spec_value_arr[i].length > 0){
			if(!vertifyStr(spec_value_arr[i])){
				showTip("规格值不能包含特殊字符",'warning');
				return false;
			}
		}
	}

	spec_value_str = spec_value_str.replace(space, "&nbsp;");

	if(!validation()){
		return false;
	}
	
	if(flag) return;
	flag = true;
	$.ajax({
		type : "post",
		url : "{:__URL('PLATFORM_MAIN/goods/updategoodsspec')}",
		data : {
			'spec_id' : spec_id,
			'spec_name' : spec_name,
			'show_type' : show_type,
			'sort' : sort,
			'is_visible' : is_visible,
			'spec_value_str' : spec_value_str,
			'is_screen' : is_screen,
			'spec_des' : spec_des
		},
		success : function(data) {
			if (data["code"] > 0) {
				showTip("修改成功","success");
				location.href = "{:__URL('PLATFORM_MAIN/goods/goodsspeclist')}";
			} else {
				showTip("修改失败","error");
				flag = false;
			}
		}
	});
}



// 验证字符串不能含有特殊字符
function vertifyStr(str){
	var regEn = /[`~!@#$%^&*()_+<>?:"{},.\/;'[\]\\]/im,
    regCn = /[·！#￥（——）：；“”‘、，|《。》？、【】[\]]/im;

	if(regEn.test(str) || regCn.test(str)) {
	    return false;
	}else{
		return true;
	}
}
</script>
{/block}